package com.ymatou.livevideo.testcase;

import java.util.Map;

import org.junit.After;
import org.junit.AfterClass;
import org.junit.Before;
import org.junit.BeforeClass;
import org.junit.Test;
import org.junit.experimental.categories.Category;

import com.ymatou.iapi.liveseller.parameter.CreateSellerLiveBean;
import com.ymatou.livevideo.parameter.ProcedureStateChanged;
import com.ymatou.livevideo.parameter.RecLiveNotifyBean;
import com.ymatou.livevideo.parameter.ReplayNotifyBean;
import com.ymatou.livevideo.parameter.Trancode;
import com.ymatou.livevideo.parameter.TrancodeOutPut;
import com.ymatou.livevideo.service.ReplayNotifyCall;
import com.ymt.core.tool.Logger;
import com.ymt.utils.annotation.*;
import com.ymt.utils.tag.*;
import com.ymttest.business.service.LiveRoomCallService;
import com.ymttest.database.model.LiveRoom;
import com.ymttest.database.sqlwapper.LiveRoomWapper;
/**
*录制文件事件处理
*FreeMaker Template自动生成代码
*/
@TestSuite
public class Ts_ReplayNotify{
	private static ReplayNotifyBean replaynotifyBean;
	private static ReplayNotifyCall replaynotifyCall;
	@BeforeClass
	public static void setUp() {
		Logger.createResultFile("录制文件事件处理");
	}

	@Before
	public void caseUp() {
		replaynotifyBean=new ReplayNotifyBean();
		replaynotifyCall=new ReplayNotifyCall();
	}

	@AfterClass
	public static void tearDown() {
		Logger.generateResult(replaynotifyCall.getOpurl());
	}

	@After
	public void caseDown() {
		Logger.end();
	}
	@Test
	@Category({P1.class})
	@TestCase
	public void Tc_ReplayNotify_001() {
		Logger.start(true,"录制文件事件处理成功");
		try {
			CreateSellerLiveBean createsellerliveBean = LiveRoomCallService.initCreatesellerliveBean(null);
			LiveRoom liveroom = LiveRoomCallService.CreateSellerLive(createsellerliveBean);
			LiveRoomCallService.UpdateLiveTimeToStart(liveroom.getId());
			Logger.comment("先推流再接受第三方通知");
			RecLiveNotifyBean recivenotifyBean = LiveRoomCallService.initRecLiveNotifyBean(liveroom.getId(), 100);
			LiveRoomCallService.LiveNotify(recivenotifyBean);
			replaynotifyBean = LiveRoomCallService.initReplayNotifyBean(liveroom.getId(),recivenotifyBean.getFile_id());
			replaynotifyCall.setData(replaynotifyBean);
			replaynotifyCall.callService();			
			Logger.verifyEquals("0", replaynotifyCall.getString("code"), "验证code");
			Map m=new LiveRoomWapper().selectLivereplayById(liveroom.getId().toString());
			Logger.debug(m);
			Trancode to=(Trancode) replaynotifyBean.getData().getProcessTaskList().get(0);
			Logger.verifyEquals(to.getOutput().getUrl(), m.get("ReplayBQUrl"), "验证ReplayBQUrl");
			Logger.verifyEquals(replaynotifyBean.getData().getFileId(), m.get("FileId").toString(), "验证FileId");
		} catch (Exception e) {
			Logger.fail(e);
		}
	}
	@Test
	@Category({P1.class})
	@TestCase
	public void Tc_ReplayNotify_002() {
		Logger.start(true,"EventType错误失败");
		try {
			CreateSellerLiveBean createsellerliveBean = LiveRoomCallService.initCreatesellerliveBean(null);
			LiveRoom liveroom = LiveRoomCallService.CreateSellerLive(createsellerliveBean);
			LiveRoomCallService.UpdateLiveTimeToStart(liveroom.getId());
			Logger.comment("先推流再接受第三方通知");
			RecLiveNotifyBean recivenotifyBean = LiveRoomCallService.initRecLiveNotifyBean(liveroom.getId(), 100);
			LiveRoomCallService.LiveNotify(recivenotifyBean);
			replaynotifyBean = LiveRoomCallService.initReplayNotifyBean(liveroom.getId(),recivenotifyBean.getFile_id());
			replaynotifyBean.setEventType("err");
			replaynotifyCall.setData(replaynotifyBean);
			replaynotifyCall.callService();			
			Logger.verifyEquals("500", replaynotifyCall.getString("code"), "验证code");
		} catch (Exception e) {
			Logger.fail(e);
		}
	}
	@Test
	@Category({P1.class})
	@TestCase
	public void Tc_ReplayNotify_003() {
		Logger.start(true,"data.errorcode错误失败");
		try {
			CreateSellerLiveBean createsellerliveBean = LiveRoomCallService.initCreatesellerliveBean(null);
			LiveRoom liveroom = LiveRoomCallService.CreateSellerLive(createsellerliveBean);
			LiveRoomCallService.UpdateLiveTimeToStart(liveroom.getId());
			Logger.comment("先推流再接受第三方通知");
			RecLiveNotifyBean recivenotifyBean = LiveRoomCallService.initRecLiveNotifyBean(liveroom.getId(), 100);
			LiveRoomCallService.LiveNotify(recivenotifyBean);
			replaynotifyBean = LiveRoomCallService.initReplayNotifyBean(liveroom.getId(),recivenotifyBean.getFile_id());
			replaynotifyBean.getData().setErrCode(-1);
			replaynotifyCall.setData(replaynotifyBean);
			replaynotifyCall.callService();			
			Logger.verifyEquals("0", replaynotifyCall.getString("code"), "验证code");
			Map m=new LiveRoomWapper().selectLivereplayById(liveroom.getId().toString());
			Logger.debug(m);
			Trancode to=(Trancode) replaynotifyBean.getData().getProcessTaskList().get(0);
			Logger.verifyNotEquals(to.getOutput().getUrl(), m.get("ReplayBQUrl"), "验证ReplayBQUrl");
		} catch (Exception e) {
			Logger.fail(e);
		}
	}
	@Test
	@Category({P1.class})
	@TestCase
	public void Tc_ReplayNotify_004() {
		Logger.start(true,"data.FileId错误失败");
		try {
			CreateSellerLiveBean createsellerliveBean = LiveRoomCallService.initCreatesellerliveBean(null);
			LiveRoom liveroom = LiveRoomCallService.CreateSellerLive(createsellerliveBean);
			LiveRoomCallService.UpdateLiveTimeToStart(liveroom.getId());
			Logger.comment("先推流再接受第三方通知");
			RecLiveNotifyBean recivenotifyBean = LiveRoomCallService.initRecLiveNotifyBean(liveroom.getId(), 100);
			LiveRoomCallService.LiveNotify(recivenotifyBean);
			replaynotifyBean = LiveRoomCallService.initReplayNotifyBean(liveroom.getId(),recivenotifyBean.getFile_id());
			replaynotifyBean.getData().setFileId("err");
			replaynotifyCall.setData(replaynotifyBean);
			replaynotifyCall.callService();			
			Logger.verifyEquals("400", replaynotifyCall.getString("code"), "验证code");
		} catch (Exception e) {
			Logger.fail(e);
		}
	}
	@Test
	@Category({P1.class})
	@TestCase
	public void Tc_ReplayNotify_005() {
		Logger.start(true,"data.processTaskList.TaskType错误失败");
		try {
			CreateSellerLiveBean createsellerliveBean = LiveRoomCallService.initCreatesellerliveBean(null);
			LiveRoom liveroom = LiveRoomCallService.CreateSellerLive(createsellerliveBean);
			LiveRoomCallService.UpdateLiveTimeToStart(liveroom.getId());
			Logger.comment("先推流再接受第三方通知");
			RecLiveNotifyBean recivenotifyBean = LiveRoomCallService.initRecLiveNotifyBean(liveroom.getId(), 100);
			LiveRoomCallService.LiveNotify(recivenotifyBean);
			replaynotifyBean = LiveRoomCallService.initReplayNotifyBean(liveroom.getId(),recivenotifyBean.getFile_id());
			Trancode sendto=(Trancode) replaynotifyBean.getData().getProcessTaskList().get(0);
			sendto.setTaskType("err");
			replaynotifyCall.setData(replaynotifyBean);
			replaynotifyCall.callService();			
			Logger.verifyEquals("0", replaynotifyCall.getString("code"), "验证code");
			Map m=new LiveRoomWapper().selectLivereplayById(liveroom.getId().toString());
			Logger.debug(m);
			Trancode to=(Trancode) replaynotifyBean.getData().getProcessTaskList().get(0);
			Logger.verifyNotEquals(to.getOutput().getUrl(), m.get("ReplayBQUrl"), "验证ReplayBQUrl");
		} catch (Exception e) {
			Logger.fail(e);
		}
	}
	@Test
	@Category({P1.class})
	@TestCase
	public void Tc_ReplayNotify_006() {
		Logger.start(true,"data.processTaskList.errorcode错误失败");
		try {
			CreateSellerLiveBean createsellerliveBean = LiveRoomCallService.initCreatesellerliveBean(null);
			LiveRoom liveroom = LiveRoomCallService.CreateSellerLive(createsellerliveBean);
			LiveRoomCallService.UpdateLiveTimeToStart(liveroom.getId());
			Logger.comment("先推流再接受第三方通知");
			RecLiveNotifyBean recivenotifyBean = LiveRoomCallService.initRecLiveNotifyBean(liveroom.getId(), 100);
			LiveRoomCallService.LiveNotify(recivenotifyBean);
			replaynotifyBean = LiveRoomCallService.initReplayNotifyBean(liveroom.getId(),recivenotifyBean.getFile_id());
			Trancode sendto=(Trancode) replaynotifyBean.getData().getProcessTaskList().get(0);
			sendto.setErrCode(-1);
			replaynotifyCall.setData(replaynotifyBean);
			replaynotifyCall.callService();			
			Logger.verifyEquals("0", replaynotifyCall.getString("code"), "验证code");
			Map m=new LiveRoomWapper().selectLivereplayById(liveroom.getId().toString());
			Logger.debug(m);
			Trancode to=(Trancode) replaynotifyBean.getData().getProcessTaskList().get(0);
			Logger.verifyNotEquals(to.getOutput().getUrl(), m.get("ReplayBQUrl"), "验证ReplayBQUrl");
		} catch (Exception e) {
			Logger.fail(e);
		}
	}
	@Test
	@Category({P1.class})
	@TestCase
	public void Tc_ReplayNotify_007() {
		Logger.start(true,"data.processTaskList.Status错误失败");
		try {
			CreateSellerLiveBean createsellerliveBean = LiveRoomCallService.initCreatesellerliveBean(null);
			LiveRoom liveroom = LiveRoomCallService.CreateSellerLive(createsellerliveBean);
			LiveRoomCallService.UpdateLiveTimeToStart(liveroom.getId());
			Logger.comment("先推流再接受第三方通知");
			RecLiveNotifyBean recivenotifyBean = LiveRoomCallService.initRecLiveNotifyBean(liveroom.getId(), 100);
			LiveRoomCallService.LiveNotify(recivenotifyBean);
			replaynotifyBean = LiveRoomCallService.initReplayNotifyBean(liveroom.getId(),recivenotifyBean.getFile_id());
			Trancode sendto=(Trancode) replaynotifyBean.getData().getProcessTaskList().get(0);
			sendto.setStatus("Failed");
			replaynotifyCall.setData(replaynotifyBean);
			replaynotifyCall.callService();			
			Logger.verifyEquals("0", replaynotifyCall.getString("code"), "验证code");
			Map m=new LiveRoomWapper().selectLivereplayById(liveroom.getId().toString());
			Logger.debug(m);
			Trancode to=(Trancode) replaynotifyBean.getData().getProcessTaskList().get(0);
			Logger.verifyNotEquals(to.getOutput().getUrl(), m.get("ReplayBQUrl"), "验证ReplayBQUrl");
		} catch (Exception e) {
			Logger.fail(e);
		}
	}
	@Test
	@Category({P1.class})
	@TestCase
	public void Tc_ReplayNotify_008() {
		Logger.start(true,"data.processTaskList.Definition错误失败");
		try {
			CreateSellerLiveBean createsellerliveBean = LiveRoomCallService.initCreatesellerliveBean(null);
			LiveRoom liveroom = LiveRoomCallService.CreateSellerLive(createsellerliveBean);
			LiveRoomCallService.UpdateLiveTimeToStart(liveroom.getId());
			Logger.comment("先推流再接受第三方通知");
			RecLiveNotifyBean recivenotifyBean = LiveRoomCallService.initRecLiveNotifyBean(liveroom.getId(), 100);
			LiveRoomCallService.LiveNotify(recivenotifyBean);
			replaynotifyBean = LiveRoomCallService.initReplayNotifyBean(liveroom.getId(),recivenotifyBean.getFile_id());
			Trancode sendto=(Trancode) replaynotifyBean.getData().getProcessTaskList().get(0);
			sendto.setStatus("Failed");
			replaynotifyCall.setData(replaynotifyBean);
			replaynotifyCall.callService();			
			Logger.verifyEquals("0", replaynotifyCall.getString("code"), "验证code");
			Map m=new LiveRoomWapper().selectLivereplayById(liveroom.getId().toString());
			Logger.debug(m);
			Trancode to=(Trancode) replaynotifyBean.getData().getProcessTaskList().get(0);
			Logger.verifyNotEquals(to.getOutput().getUrl(), m.get("ReplayBQUrl"), "验证ReplayBQUrl");
		} catch (Exception e) {
			Logger.fail(e);
		}
	}
}